Node3D plugin example
This example shows how to create a custom 3D node and how to use that node in Kanzi Studio. The Kanzi example contains a Visual Studio solution that defines the .dll for the Kanzi Engine plugin which defines the custom node, and a Kanzi Studio project that uses the plugin system to apply in the Kanzi Studio Preview the behaviors defined in the custom nodes.
You can find the example in the <KanziWorkspace>/Examples/Node3D_plugin directory.
To learn how to create a Kanzi Engine plugin, see Creating Kanzi Engine plugins.
Creating custom nodes
The two custom nodes in the example are:
- Knob reacts to user input by sending messages about the current rotation angle of the knob. It generates its own messages based on the user input (pan gestures). Knob generates these message types intercepted in Kanzi Studio at the Knob:
- Rotation of the knob is forwarded to the external visualization of the knob by passing the argument directly to its Z-rotation attribute.
- Discrete level updates are treated by generating application events (also messages), which are passed to the Spinner node.
- Spinner reacts to messages by updating the Text property of the Text Block node, to show the value from the Knob. It receives messages from the outside and reacts to the messages based on its own defined behavior.
Kanzi Studio reads from the plugin dll the information about the messages and property types used by the custom nodes.
Kanzi Engine registers the plugin by calling a function with this signature from the plugin
extern "C"
{
__declspec(dllexport) Module* createModule(uint32_t kanziVersionMajor, uint32_t kanziVersionMinor);
}
Knob and Spinner nodes are registered in the getMetaclassesOverride() function which is defined in the module that you create and that the createModule() function returns.
In order to register the Spinner node, the Spinner must contain a metaclass. By using the KZ_METACLASS_BEGIN you define a custom node and there you declare:
- Base class (
Node3D) - Unique ID (
"Spinner") - Messages it uses (
SpinnerUpdateLevelMessage) - Property types it uses (
TextBlockProperty)
KZ_METACLASS_BEGIN(Spinner, Node3D, "Spinner")
KZ_METACLASS_MESSAGE_TYPE(SpinnerUpdateLevelMessage)
KZ_METACLASS_PROPERTY_TYPE(TextBlockProperty)
KZ_METACLASS_END()
In this example the Spinner creates its message type SpinnerUpdateLevelMessage by specifying that it uses SpinnerUpdateLevelMessageArguments.
MessageType<Spinner::SpinnerUpdateLevelMessageArguments> Spinner::SpinnerUpdateLevelMessage(kzMakeFixedString("Message.Spinner.UpdateLevel"),
KZ_DECLARE_EDITOR_METADATA
(
// Set the name of the message the way it is shown in Kanzi Studio.
metadata.displayName = "Update Spinner Level";
// Set the tooltip for the message.
metadata.tooltip = "Updates the Spinner level and outputs the level to a text block.";
// Do not show the message as a trigger.
// Do this when you want to show a message in Kanzi Studio as an action.
metadata["Listenable"] = "False";
));
In order to register the message arguments for the SpinnerUpdateLevelMessage the SpinnerUpdateLevelMessageArguments must contain the metaclass that defines the message arguments. By using the KZ_MESSAGE_ARGUMENTS_METACLASS_BEGIN you define the argument for the custom message and there you declare:
- Base class (
MessageArguments) - Unique ID (
"Spinner Update Level Message Arguments") - Property type (
SpinnerLevelAlterationProperty)
KZ_MESSAGE_ARGUMENTS_METACLASS_BEGIN(SpinnerUpdateLevelMessageArguments, MessageArguments, "Spinner Update Level Message Arguments")
KZ_METACLASS_PROPERTY_TYPE(SpinnerLevelAlterationProperty)
KZ_METACLASS_END()
See also
Extending the functionality of Kanzi Engine
Reference for showing Kanzi Engine plugin custom types in Kanzi Studio